var App = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    role_id:wx.getStorageSync('role_id'),
    domain:App.globalData.iconsUrl,
    list:[],
    playData:{},
  },
  //  生命周期函数--监听页面加载
  onLoad(options) {},
  // 生命周期函数--监听页面初次渲染完成
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // 获取数据列表
    this.getDataList();
  },
  //获取数据列表
  getDataList(){
    let that = this;
    let obj = {b_id:App.get_b_id()}
    App.request('/Manage/Management/storeSiteList',obj,function(e){
      wx.stopPullDownRefresh()
        if (e.code == "200") {
          that.setData({list:e.result})
        } 
    })
  },
  // textarea 触发赋值
  bindinput(e){
    console.log(e)
    let key = e.currentTarget.dataset.type+e.currentTarget.dataset.id
    let playData = this.data.playData
    playData[key] = e.detail.value
    this.setData({playData})
  },
  // 喊话
  play(e){
     let key = e.currentTarget.dataset.type+e.currentTarget.dataset.id
     let obj={
        site_id:e.currentTarget.dataset.id,
        voice:this.data.playData[key]==undefined?'':this.data.playData[key],
        type:e.currentTarget.dataset.type,
     }
      App.request('/Manage/Management/playTips',obj,function(e){
        if (e.code == "200") {
          App.showSuccessToast(e.msg);
        } 
      })
  },
  // 提交保存
  submit(e){
    console.log(e)
      let data =e.detail.value
      let that =  this
      let obj = {
        site_id:e.currentTarget.dataset.id,
        start_voice:data.start_voice==true?1:0,
        saoma_voice:data.saoma_voice==true?1:0,
        leave_voice:data.leave_voice==true?1:0,
        enough_voice:data.enough_voice==true?1:0,
        into_voice:data.into_voice,
        voice_one:data.voice_one,
        voice_two:data.voice_two,
      }
      App.request('/Manage/Management/setHorn',obj,function(e){
          if (e.code == "200") {
            App.showSuccessToast(e.msg, function() {
              that.getDataList()          //刷新列表
            });
          } 
      })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getDataList();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})